//
//  GWMyHomeBtn.m
//  新浪微博
//
//  Created by qianfeng on 16/1/9.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWMyHomeBtn.h"

@implementation GWMyHomeBtn
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        self.imageView.contentMode =UIViewContentModeCenter;
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.adjustsImageWhenHighlighted =NO;
        self.titleLabel.font =[UIFont boldSystemFontOfSize:17];
        self.titleLabel.textAlignment =NSTextAlignmentRight;
    }
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat titleX =0;
    CGFloat titleY =0;
    CGFloat titleH =contentRect.size.height;
    CGFloat titleW =contentRect.size.width-titleH;
    return CGRectMake(titleX, titleY, titleW, titleH);
}
-(CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat imageH =contentRect.size.height;
    CGFloat imageW =imageH;
    CGFloat imageX =contentRect.size.width-imageW;
    CGFloat imageY =0;
    return CGRectMake(imageX, imageY, imageW, imageH);
}
-(void)setTitle:(NSString *)title forState:(UIControlState)state
{
    [super setTitle:title forState:state];
  
    
    self.width =[title boundingRectWithSize:CGSizeMake(300, 35) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.titleLabel.font} context:nil].size.width+self.height+10;
}
@end
